package com.wx.forum.dao;

import com.wx.forum.model.Article;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ArticleMapper {
    int insert(Article row);

    int insertSelective(Article row);

    Article selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Article row);

    int updateByPrimaryKeyWithBLOBs(Article row);

    int updateByPrimaryKey(Article row);

    /**
     * 查询所有合法帖子
     * @return
     */
    List<Article> selectAll();

    /**
     * 根据boardId查询所有帖子
     * @param boardId
     * @return
     */
    List<Article> selectAllByBoardId(@Param("boardId") Long boardId);

    /**
     * 根据帖子id查询帖子详情
     * @param id
     * @return
     */
    Article selectDetailById(@Param("id") Long id);

    /**
     * 根据用户id查询帖子列表
     * @param userId
     * @return
     */
    List<Article> selectArticleByUserId(@Param("userId") Long userId);

    /**
     * 根据关键词key查询对应帖子
     * @param key
     * @return
     */
    List<Article> searchArticle(@Param("key") String key);

    @Update("update t_article set likeCount = likeCount + #{value} where id = #{articleId}")
    void updateLikeCount(Long articleId, Integer value);
}